package com.app.micaihu.bean.news;

import android.provider.Telephony;
import android.view.View;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;


/**
 * 三张图片
 * Created by linkai on 2016/7/18.
 */
public class ViewNewsThreeImg extends ViewNewsParent {

    public CustomImageView oneImg;
    public CustomImageView twoImg;
    public CustomImageView threeImg;

    private int width = 324;
    private int height = 232;
    private TextView picNum;


    public ViewNewsThreeImg(View convertView) {
        initView(convertView);
    }

    public ViewNewsThreeImg(View convertView,int width,int height) {
        this.width = width;
        this.height = height;
        initView(convertView);
    }

    /**
     * 初始化控件
     * @param convertView
     */
    public void initView(View convertView) {
        super.initView(convertView);

        this.oneImg = (CustomImageView) convertView.findViewById(R.id.item_image_0);
        this.twoImg = (CustomImageView) convertView.findViewById(R.id.item_image_1);
        this.threeImg = (CustomImageView) convertView.findViewById(R.id.item_image_2);
        ViewSizeUtils.changeViewAuto1080(this.oneImg, width, height);
        ViewSizeUtils.changeViewAuto1080(this.twoImg, width, height);
        ViewSizeUtils.changeViewAuto1080(this.threeImg,width,height);


        picNum = (TextView) convertView.findViewById(R.id.thumb_num);
        if(picNum != null){
            picNum.setVisibility(View.GONE);
        }
        convertView.setTag(this);
    }

    /**
     * 加载数据
     * @param newsEntity
     */
    public void loadData(NewsEntity newsEntity){
        super.loadData(newsEntity);
//        for(int i=0;i<newsEntity.getArticleThumb().length;i++){
//            if(TextUtils.isEmpty(newsEntity.getArticleThumb()[i])){
//                this.oneImg.
//            }else{
//                LoadImageUtils.getInstance().loadWifiImage(this.oneImg, newsEntity.getArticleThumb()[i]);
//            }
//        }

        LoadImageUtils.getInstance().loadWifiImage(this.oneImg, newsEntity.getArticleThumb()[0]);
        LoadImageUtils.getInstance().loadWifiImage(this.twoImg, newsEntity.getArticleThumb()[1]);
        LoadImageUtils.getInstance().loadWifiImage(this.threeImg, newsEntity.getArticleThumb()[2]);


        if(picNum != null){
            if(TypeConstant.SHOP_ALI_PIC.equals(newsEntity.getArticleType())){//是商品三图的

                if(newsEntity.getArticleThumb().length > 3){
                    picNum.setVisibility(View.VISIBLE);
                    picNum.setText(newsEntity.getArticleThumb().length + "图");
                }else{
                    picNum.setVisibility(View.GONE);
                }
            }else{
                picNum.setVisibility(View.GONE);
            }
        }


    }






    /**
     * 加载数据
     * @param newsEntity
     * @param matchStr
     */
    public void loadData(NewsEntity newsEntity, String matchStr){
        loadData(newsEntity);
        super.matchTitle(newsEntity.getArticleTitle(),matchStr);
    }

}
